import { AjaxService, Req, Res } from "./ajax.service"
import { Injectable } from '@angular/core'

import { Type } from "./type"

@Injectable()
export class TypeService {
  private bh = AjaxService.APIROOT + '/projects/types';
  public static ALL: Array<Type>

  getList(): Promise<Array<Type>> {
    return new Promise<Array<Type>>(resolve => {
        if (TypeService.ALL) resolve()
        AjaxService.request(new Req(`${this.bh}.json`, "GET"))
          .then(res => {
            if (!res.error)
              TypeService.ALL = res.data
            resolve()
          }).catch((err: any) => { console.log("get types error", err) })
      }).then(() => TypeService.ALL)
  }
}
